package com.cc.eb.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cc.eb.mapper.EbNewsMapper;
import com.cc.eb.mapper.EbProductMapper;
import com.cc.eb.model.EbNews;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 用一句话描述
 * @Auther: 新梦想*陈超
 * @Date: 2022/1/7 10:46
 */
@Service//证
//@Slf4j
public class IndexService {//业务员
    @Resource
    private EbProductMapper ebProductMapper;

    @Resource
    private EbNewsMapper newMapper;
    /*查询首页所有的数据 */
    public Map<String, Page> index(int page,int pageSize){
        //log.info();
        System.out.println("进入IndexService 的index方法 =====");
        Map<String,Page> result= new HashMap<>();
        //TODO 1.调用mapper查询商品分页数据 page=1 pageSize= 8
        Page  page1= new Page(page,pageSize);
        Page productPage = ebProductMapper.selectPage(page1, null);
        System.out.println("查询 商品数据为："+productPage);
        //TODO 2.调用mapper查询新闻分页数据
        page1 =  new Page(1,8);
        Page newsPage =newMapper.selectPage(page1,new QueryWrapper<EbNews>()
                .orderByDesc("en_create_time"));
        //TODO 3.调用mapper查询商品分类分页数据----不能写到这里
        //将所有数据到result中
        result.put("productPage",productPage);
        result.put("newsPage",newsPage);
        return  result;
    }

}
